<template>
	<el-config-provider :size="getGlobalComponentSize" :button="config" :locale="state.i18nLocale">
		<router-view v-show="getThemeConfig.lockScreenTime !== 0" />
		<LockScreen v-if="getThemeConfig.isLockScreen" />
		<Settings ref="settingsRef" v-show="getThemeConfig.lockScreenTime !== 0" />
		<CloseFull />
	</el-config-provider>
</template>

<script lang="ts" setup>
import { computed, getCurrentInstance, nextTick, onBeforeMount, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
import { store } from "@/store"
import CloseFull from "@/components/layout/navBars/closeFull.vue";
import Settings from '@/components/layout/navBars/settings.vue';
import LockScreen from '@/components/layout/lockScreen/index.vue';
import { Catch, Tools } from '@/utils'
import { useRoute } from 'vue-router';
import { useTitle } from './hooks';
import setIntroduction from '@/utils/setIconfont';

const route = useRoute();
const title = useTitle();
const settingsRef = ref();

const config = reactive({
	autoInsertSpace: true,
})
const state = reactive({
	i18nLocale: null,
})

const { proxy } = <any>getCurrentInstance();

// 获取布局配置信息
const getThemeConfig = computed(()=>store.state.themeConfig.themeConfig)
// 获取全局组件大小
const getGlobalComponentSize = computed(() =>Tools.globalComponentSize);
// 布局配置弹窗打开
const openSettingsDrawer = () => {
	settingsRef.value.openDrawer();
};

// 设置初始化，防止刷新时恢复默认
onBeforeMount(() => {
	// 设置批量第三方 icon 图标
	setIntroduction.cssCdn();
	// 设置批量第三方 js
	setIntroduction.jsCdn();
});
onMounted(()=>{
	nextTick(() => {
		// 监听布局配置弹窗点击打开
		proxy.mittBus.on('openSettingsDrawer', () => {
			openSettingsDrawer();
		});
		// 设置 i18n，App.vue 中的 el-config-provider
		proxy.mittBus.on('getI18nConfig', (locale: string) => {
			(state.i18nLocale as string | null) = locale;
		});
		// 获取缓存中的布局配置
		if (Catch.get('themeConfig')) {
			store.dispatch('themeConfig/setThemeConfig', Catch.get('themeConfig'));
			document.documentElement.style.cssText = Catch.get('themeConfigStyle');
		}
		// 获取缓存中的全屏配置
		if (Catch.get('isTagsViewCurrenFull')) {
			store.dispatch('tagsViewRoutes/setCurrenFullscreen', Catch.get('isTagsViewCurrenFull'));
		}
	});
})
// 页面销毁时，关闭监听布局配置/i18n监听
onUnmounted(() => {
	proxy.mittBus.off('openSettingsDrawer', () => {});
	proxy.mittBus.off('getI18nConfig', () => {});
});
// 监听路由的变化，设置网站标题
// watch(
// 	() => route.path,
// 	() => {
// 		title
// 	}
// );
watch(route,()=>{
	title()
})
</script>

<style>
</style>
